function debounce(fn,s){
    let time = null;
    return function(...arg){
        if(time){
            clearTimeout(time);
        }
        time = setTimeout(fn.apply(this,arg),s)
    }
}

function throttle(fn,delay){
    let valid = true;
    return function(...arg){
        if(!valid){
            // 休息时间 咱不接客
            return false;
        }
        // 工作时间，执行函数并且在间隔期把状态位设置为无效
        valid = false;
        setTimeout(() => {
            fn.apply(this,arg);
            valid = true;
        },delay)
    }
}

function throttle2(fn,delay){
    let prev = new Date();
    return function(...args){
        let now = new Date();
        if(now - prev > delay){
            fn.apply(this,args);
            prev = new Date();
        }
    }
}
